package com.dayatang.android.Activity;

import android.content.res.Configuration;
import android.os.Bundle;

import com.dayatang.android.Adapter.DMWorkstationAdapter;
import com.dayatang.android.Adapter.PMOWorkstationAdapter;
import com.dayatang.android.Adapter.PMWorkstationAdapter;
import com.dayatang.android.Adapter.UserWorkstationAdapter;
import com.dayatang.android.config.Config;
import com.dayatang.android.config.LocationConfig;
import com.dayatang.android.widget.CircleFlowIndicator;
import com.dayatang.android.widget.ViewFlow;

public class WorkstationOfPMOActivity extends BaseActivity {
	
	private ViewFlow viewFlow;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.workstation_pmo_activity);
		InitView();
	}
	
	private void InitView() {
		viewFlow = (ViewFlow) findViewById(R.id.pmo_viewflow);
		SetWorkstationAdapter();
		CircleFlowIndicator circleFlowIndicator = (CircleFlowIndicator) findViewById(R.id.pmo_viewflowindic);
		viewFlow.setFlowIndicator(circleFlowIndicator);
	}
	
	private void SetWorkstationAdapter() {
		String role = getRole();
		if (role.equals("ROLE_PMO")) {
			viewFlow.setAdapter(new PMOWorkstationAdapter(this,getServerAddress(),getUser().getUsername()), Config.ZERO);
		} else if (role.equals("ROLE_DM")) {
			viewFlow.setAdapter(new DMWorkstationAdapter(this,getServerAddress(),getUser().getUsername()), Config.ONE);
			ReportLocation();
		} else if (role.equals("ROLE_PM")) {
			viewFlow.setAdapter(new PMWorkstationAdapter(this,getServerAddress(),getUser().getUsername()), Config.ONE);
			ReportLocation();
		} else if (role.equals("ROLE_USER")) {
			viewFlow.setAdapter(new UserWorkstationAdapter(this,getServerAddress(),getUser().getUsername()), Config.ZERO);
			ReportLocation();
		} else {
			viewFlow.setAdapter(new PMOWorkstationAdapter(this,getServerAddress(),getUser().getUsername()), Config.ZERO);
		}
	}
	
	private void ReportLocation() {
		LocationConfig.reportLocation(getServerAddress(), getUser().getUsername(), this);
	}
	
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
		viewFlow.onConfigurationChanged(newConfig);
	}
	
}
